package com.wd.tech.activity.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.wd.tech.R;
import com.wd.tech.activity.adaptert.FlowAdapter;
import com.wd.tech.activity.flowlayout.FlowLayout;

import java.util.ArrayList;
import java.util.List;

public class FlowLayoutActivity extends AppCompatActivity {
    private static final String TAG = "TestActivity";
    private FlowLayout mFlowLayout;
    private List<String> mContentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flow_layout);

        initData();
        initView();
    }

    private void initData() {
        for (int i = 0; i < 9; i++) {
            mContentList.add("区块链");
            mContentList.add("中年危机");
            mContentList.add("锤子科技");
            mContentList.add("子弹短信");
            mContentList.add("民营企业");
            mContentList.add("特斯拉");
            mContentList.add("支付宝");
            mContentList.add("资本市场");
            mContentList.add("电视剧");
        }
    }

    private void initView() {
        mFlowLayout = findViewById(R.id.fv_test_flow_layout);
        // 设置 Adapter
        FlowAdapter adapter = new FlowAdapter(this, mContentList);
        mFlowLayout.setAdapter(adapter);
        // 设置最多显示的行数
        mFlowLayout.setMaxLines(3);
        // 获取显示的 item 数
        mFlowLayout.post(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "count = " + mFlowLayout.getVisibleItemCount());
            }
        });

    }
}
